home *** CD-ROM | disk | FTP | other *** search
- Path: locutus.rchland.ibm.com!usenet
- From: Philip Staite <pstaite+@rchland.ibm.com>
- Newsgroups: comp.lang.c++
- Subject: Re: 'new' & 'delete' memory management
- Date: Wed, 27 Mar 1996 07:57:17 -0600
- Organization: IBM Rochester, MN
- Message-ID: <3159493D.167E@rchland.ibm.com>
- References: <4j81ce$ivk@umt.umt.edu>
- NNTP-Posting-Host: powertool.rchland.ibm.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (X11; I; AIX 1)
-
- Ho Hsin wrote:
-
- > 1) How do new and delete manage memory at a low level (ie. the internal
- > working of new and delete.)
-
- Many don't ;-) Many C++ RTL implementations just call malloc and free
- from the C RTL under the covers. Your question is a little broad, what
- exactly do you want to know? Allocation strategy, deallocation and
- fragmentation recovery? Block chains vs directory list? Minimum
- allocation size and space overhead? Paging strategy?...
-
- Finally, implementations can and do vary quite a bit. There are lots of
- good ways of "managing" memory within new/delete malloc/free with
- various tradeoffs.
-
-
- > 2) Does it coalesce small blocks of memory after delete to prevent
- > fragmentations? How does it do it (ie. algorithm) ?
-
- Yes, no, maybe, sometimes... Depends on the system and library. Some
- policies in use are:
-
- 1) Always concatenate on the free.
-
- 2) Concatenate on the allocate (ie, is this free block too small? Is
- there another adjacent free block?...)
-
- 3) Don't concatenate (ever, but use a best-fit allocation scheme).
-
- 4) Concatentate only when there are no more free blocks available of
- sufficent size.
-
- 5) etc. -- probably a couple I've forgotten about.
-
- > 3) Page or virtual memory is handled by the OS of the system. I would
- > like to know how is memory manage within a page?
-
- On some systems it isn't. That is, the smallest allocation unit from
- the OS is a page (typically 4096 bytes). The C/C++ RTL will get memory
- from the OS in multi-page "chunks" and then suballocate it as needed.
- On other systems the RTL may be "lazy" and let the OS memory manager do
- all the work.
-
- --
-
- Phil Staite, (507) 253-2529, team OS/2
- internet: pstaite@vnet.ibm.com internal: pstaite@rchland
-